package com.team.mr.mrboot.controller;

import com.team.mr.mrboot.entity.Subject;
import com.team.mr.mrboot.result.ResponseCode;
import com.team.mr.mrboot.result.ResponseData;
import com.team.mr.mrboot.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-06-01 10:38:17
 */
@Api(value = "subjectApi")
@RestController
@RequestMapping("subject")
public class SubjectController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectService subjectService;

    @ApiOperation(value ="queryAll",notes = "查询所有项目")
    @GetMapping("queryAll")
    public ResponseData queryAll(){
        List<Subject> list=subjectService.queryAll();
        if(list==null){
            return new ResponseData(ResponseCode.FAILED,null);
        }else {
            return new ResponseData(ResponseCode.SUCCESS,list);
        }
    }
    @ApiOperation(value ="queryById",notes = "通过id查询项目")
    @ApiImplicitParam(name = "id",value = "id")
    @GetMapping("queryById/{id}")
    public ResponseData queryById(@PathVariable Integer id){
        Subject subject=subjectService.queryById(id);
        if(subject==null){
            return new ResponseData(ResponseCode.FAILED,null);
        }else {
            return new ResponseData(ResponseCode.SUCCESS,subject);
        }
    }
    @ApiOperation(value ="queryByTitle",notes = "通过项目名称查询")
    @ApiImplicitParam(name = "title",value = "title")
    @GetMapping("queryByTitle/{title}")
    public ResponseData queryByTitle(@PathVariable String title){
        List<Subject> subject=subjectService.queryByTitle(title);
        if(subject==null){
            return new ResponseData(ResponseCode.FAILED,null);
        }else {
            return new ResponseData(ResponseCode.SUCCESS,subject);
        }
    }
}
